package DecChallenges;

//滑动窗口
//https://leetcode.com/problems/largest-3-same-digit-number-in-string/description/?envType=daily-question&envId=2023-12-04
public class Day4_P2264 {
    public static void main(String[] args) {
        String num = "6777133339";
        Day4_P2264 q = new Day4_P2264();
        String s = q.largestGoodInteger(num);
        System.out.println(s);
    }
    public String largestGoodInteger(String num) {
        char[] str = num.toCharArray();
        int R = 1, accu = -1, ans = -1;
        boolean flag = true;
        for(int L = 0; L < str.length;) {
            accu = str[L] - '0';
            while(R < str.length && R - L + 1 <= 3) {
                if(str[R] != str[R - 1]) {
                    flag = false;
                    break;
                }
                accu = accu * 10 + (str[R] - '0');
                R++;
            }
            if(flag && R - L == 3) {
                ans = Math.max(ans, accu);
            }
            L = R;
            R++;
            flag = true;
        }
        return ans == -1 ? "" : ans == 0 ? "000" : String.valueOf(ans);
    }
}
